﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Department.aspx.cs" Inherits="Skyworth.CRM.Web.BasicData.Department" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>组织结构管理</title>
    <%--[if IE]>
     <link href="../themes/css/ieHack.css" rel="stylesheet" type="text/css" />
    <![endif]--%>
    <link href="../themes/default/style.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/core.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/pages.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/Messagebox.css" rel="stylesheet" type="text/css" />

    <script src="../javascripts/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="../javascripts/MessageBox.js" type="text/javascript"></script>

    <script src="../javascripts/dwz.core.js" type="text/javascript"></script>

    <script src="../javascripts/dwz.tree.js" type="text/javascript"></script>

    <style type="text/css">        
        a
        {
            display: block;
        }
        .red
        {
            color: Red;
            font-weight: bold;
        }       
        table
        {
            border-collapse: collapse;
            border-spacing: 0;
            table-layout: fixed;
            width: 100%;
            border: solid 1px #AAA;
        }
        table tr td
        {
            border-bottom: solid 1px #AAA;
            padding: 0px 3px;
            background-color: #EFEFEF;
        }
        td label
        {
            padding: 2px 2px;
        }
        td.left
        {
            border-right: solid 1px #AAA;
            width: 65px;
        }
        td.right
        {
            background: #FFF;
        }
        td.right, td.readOnly
        {
            padding: 5px 3px;
        }
        .txt
        {
            border: 1px solid #C3C3C3;
            color: #333333;
            font-family: Arial,Verdana,Helvetica,sans-serif;
            height: 20px;
            line-height: 20px;
            width: 290px;
        }
        .content
        {
            overflow: auto;
            min-height: 350px;
            _height: 350px;
            border: solid 1px #CCC;
            line-height: 21px;
            background: #FFF;
            padding: 5px;
        }
        
    </style>

    <script type="text/javascript">
        function SaveCheck() {
            var objDepartName = $("#txtDepartmentName");
            var name = objDepartName.val();
            if (name == "" || name.length <= 0) {
                alert("请输入组织名称！");
                objDepartName.focus();
                return false;
            }
        }


        $(document).ready(function() {
            $("ul.tree").jTree();
            $("input[type=text]").addClass("textInput").focus(function() { $(this).addClass("focus"); }).blur(function() { $(this).removeClass("focus") });

            $("div.button").hover(function() { $(this).addClass("buttonHover"); },
                                 function() { $(this).removeClass("buttonHover"); });
            $("div.buttonActive").hover(function() { $(this).addClass("buttonActiveHover"); },
                                function() { $(this).removeClass("buttonActiveHover"); })

            $("#btnUpdate").click(function() {
                var deptId = $("ul.tree div.selected a").attr("tvalue");
                if (!deptId || parseInt(deptId) <= 0) {
                    $.Messager.Alert({ Title: '系统消息', Message: "请选择要修改的节点！", Icon: IconType.Warning });
                    return false;
                }
                return SaveCheck();
            })

            $("#btnDelete").click(function() {
                if ($(this).attr("disabled") != "disabled") {
                    var deptId = $("ul.tree div.selected a").attr("tvalue");
                    if (deptId && parseInt(deptId) > 0) {
                        $.Messager.Confirm({ Title: '系统警告', Message: '删除该节点时会同时删除它的所有子节点，你确定真的要删除吗？', Icon: IconType.Question,
                            Oncallback: function(IsYes, siteMapId) {
                                if (IsYes) { $("#btnhidDelete").trigger("click"); }
                            }
                        })
                        return false;
                    }
                    else {
                        $.Messager.Alert({ Title: '系统消息', Message: "请选择要删除的节点！", Icon: IconType.Warning });
                        return false;
                    }
                }
                return false;
            })

            //[id!='rootNode']
            $("ul.tree li a").click(function() {
                $("#txtHidDeptId").val($(this).attr("tvalue"));
                $("#txtHidParentId").val($(this).attr("tname"));
                $("#txtHidLevel").val($(this).attr("tlevel"));
                $("#txtDepartmentName").val($(this).text());
                $("#txtDescription").text($(this).attr("title"));
                if ($(this).attr("id") == "rootNode") {
                    $("#btnUpdate").attr("disabled", "disabled");
                    $("#btnAddSameLevel").attr("disabled", "disabled");
                    $("#btnDelete").attr("class", "buttonDisabled");
                    return false;
                }
                else {
                    $("#btnUpdate").removeAttr("disabled");
                    $("#btnAddSameLevel").removeAttr("disabled");
                    $("#btnDelete").attr("class", "button");
                }
            })

            $("#btnAddSameLevel,#btnAddSubNode").click(function() {
                var deptId = $("ul.tree div.selected a").attr("tvalue");
                if (!deptId || parseInt(deptId) < 0) {
                    $.Messager.Alert({ Title: '系统消息', Message: "请选择参照节点！", Icon: IconType.Warning });
                    return false;
                }
                return SaveCheck();
            })

            $("#btnClear").click(function() {
                $("#txtHidDeptId").val("");
                $("#txtHidParentId").val("");
                $("#txtHidLevel").val("");
                $("#txtDepartmentName").val("");
                $("#txtDescription").text("");
                $("ul.tree div.selected").removeClass("selected");
            })

            // $("ul.tree li a[tvalue='<%= this.txtHidDeptId.Value%>']").parent(0).addClass("selected");

            if ($.browser.msie && /6.0/.test(navigator.userAgent)) {
                try {
                    document.execCommand("BackgroundImageCache", false, 1);
                } catch (e) {
                }
            }
            //清理浏览器内存,只对IE起效
            if ($.browser.msie) {
                window.setInterval("CollectGarbage();", 10000);
            }
        })
    </script>

</head>
<body style="text-align: left; background-color: White;overflow:visible" >
    <div >
        <form id="form1" runat="server">
        <div style="min-width: 200px; width: 200px;float: left;margin: 15px 5px;">
            <div class="panel" >
                <div class="panelHeader">
                    <div class="panelHeaderContent">
                        <h1>
                            组织结构目录</h1>
                    </div>
                </div>
                <div class="panelContent">
                    <div class="content" >
                        <ul class="tree treeFolder expand">
                           <li><a id="rootNode" href="javascript:void(0)" target="navTab" tname="0" tvalue="0" checked="true" tlevel="0" title="创维电器">
                                创维电器</a>
                                <asp:Literal ID="litTreeView" runat="server"></asp:Literal>                          
                           </li>
                        </ul>
                    </div>
                </div>
                <div class="panelFooter">
                    <div class="panelFooterContent">
                        <asp:HiddenField ID="txtHidDeptId" runat="server" />
                        <asp:HiddenField ID="txtHidParentId" runat="server" />
                        <asp:HiddenField ID="txtHidLevel" runat="server" />
                    </div>
               </div> 
           </div>
        </div>
        
        <div style="min-width: 500px; width: 500px;float: left;margin: 15px 5px;">
            <div class="panel" >
                <div class="panelHeader">
                    <div class="panelHeaderContent">
                        <h1>
                            组织结构信息</h1>
                    </div>
                </div>
                <div class="panelContent">
                    <div class="content" >
                        <table width="100%">
                            <tr>
                                <td class="left">
                                    <label for="txtDepartmentName">
                                        组织名称：</label>
                                </td>
                                <td class="right">
                                    <asp:TextBox ID="txtDepartmentName" CssClass="txt" runat="server" MaxLength="50" title="请输入组织名称!"></asp:TextBox><em
                                        class="red">*</em>
                                   
                                </td>
                                
                            </tr>
                            <tr>
                                <td class="left">
                                    <label for="txtDescription">
                                        说明：</label>
                                </td>
                                <td class="right">
                                    <asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" MaxLength="100"
                                        Rows="5" Columns="10" Style="width: 285px; font-size: small;"></asp:TextBox>
                                       
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2" class="readOnly" style="padding-right: 12px; background: url('../themes/default/images/grid/grid.png') repeat scroll 0 0">
                                   <a title="清空" href="javascript:void(0)" class="button" style="float:left" id="btnClear"><span>清空</span></a>
                                   <asp:LinkButton ID="btnDelete" title="删除该节点"  runat="server" CssClass="button" CommandArgument="4" style="float:left;margin-left: 10px;"><span>删除该节点</span> </asp:LinkButton>
                                  
                                   <asp:Button ID="btnhidDelete" runat="server" Text="" style="display:none;" OnClick="btnhidDelete_Click" CommandArgument="4" />
                                    
                                     <div class="button" style="float: left; margin-left:5px;">
                                        <div class="buttonContent">
                                            <asp:Button ID="btnUpdate" runat="server" Text="修改该节点" CssClass="serverButton" onclick="btnUpdate_Click" CommandArgument="3" Width="68px" />
                                        </div>
                                    </div>                                 
                                    
                                        
                                    <div class="button" style="float: left; margin-left: 5px;">
                                        <div class="buttonContent">
                                            <asp:Button ID="btnAddSameLevel" runat="server" Text="添加为同级节点" CommandArgument="2" 
                                                CssClass="serverButton" onclick="btnAddSameLevel_Click" Width="90px" />
                                        </div>
                                    </div>
                                    <div class="button" style="float: left;margin-left: 5px;">
                                        <div class="buttonContent">
                                            <asp:Button ID="btnAddSubNode" runat="server" Text="添加为下级节点" CommandArgument="2" 
                                                CssClass="serverButton" onclick="btnAddSubNode_Click" Width="90px" />
                                        </div>
                                    </div>
                                    <div style="clear:both;float:none"></div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="panelFooter">
                <div class="panelFooterContent">
                </div>
            </div>
            </div>
        </div>
        <div style="clear:both;float:none"></div>
        </form>
    </div>
</body>
</html>
